﻿// <copyright file="Image.cs" company="Signal Processing Lab, Wuhan University">
// Copyright (c) 2009-2010 All Right Reserved
// </copyright>
// <author>Xinping Deng</author>
// <email>dentoby@gmail.com</email>
// <date>2010-4</date>
// <summary>This is part of Image.NET project.</summary>

namespace SPLWHU.Core.Raster
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// The summary of the class Image.
    /// </summary>
    /// <typeparam name="T">The data type.</typeparam>
    public class Image<T> : IImage
    {
        /// <summary>
        /// The image data.
        /// </summary>
        private Matrix<T>[] imageData;

        /// <summary>
        /// The image header.
        /// </summary>
        private TagCollection imageHeader;

        /// <summary>
        /// Initializes a new instance of the <see cref="Image&lt;T&gt;"/> class.
        /// </summary>
        /// <param name="band">The band data.</param>
        public Image(Matrix<T> band)
        {
            this.imageData = new Matrix<T>[1];
            this.imageData[0] = band;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Image&lt;T&gt;"/> class.
        /// </summary>
        /// <param name="r">The band r.</param>
        /// <param name="g">The band g.</param>
        /// <param name="b">The band b.</param>
        public Image(Matrix<T> r, Matrix<T> g, Matrix<T> b)
        {
            this.imageData = new Matrix<T>[3];
            this.imageData[0] = r;
            this.imageData[1] = g;
            this.imageData[2] = b;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Image&lt;T&gt;"/> class.
        /// </summary>
        /// <param name="bands">The band data.</param>
        public Image(Matrix<T>[] bands)
        {
            this.imageData = bands;
        }

        /// <summary>
        /// Gets the width of the image.
        /// </summary>
        /// <value>The width of the image.</value>
        public int ImageWidth
        {
            get { throw new NotImplementedException(); }
        }

        /// <summary>
        /// Gets the height of the image.
        /// </summary>
        /// <value>The height of the image.</value>
        public int ImageHeight
        {
            get { return this.imageData[0].Rows; }
        }

        /// <summary>
        /// Gets the band count of the image.
        /// </summary>
        /// <value>The band count of the image.</value>
        public int BandCount
        {
            get { return this.imageData.Length; }
        }

        /// <summary>
        /// Gets the image data.
        /// </summary>
        /// <value>The image data.</value>
        public object ImageData
        {
            get { return this.imageData; }
        }

        /// <summary>
        /// Gets the type of the data.
        /// </summary>
        /// <value>The type of the data.</value>
        public Type DataType
        {
            get { return typeof(T); }
        }

        /// <summary>
        /// Gets or sets the image header.
        /// </summary>
        /// <value>The image header.</value>
        public TagCollection Attributes
        {
            get
            {
                return this.imageHeader;
            }

            set
            {
                this.imageHeader = value;
            }
        }

        /// <summary>
        /// Applies the filter on this image.
        /// </summary>
        /// <param name="filter">The filter.</param>
        public void ApplyFilter(IFilter filter)
        {
            filter.Apply(this.imageHeader, this.imageData);
        }
    }
}
